// pages/user/login/login.js
var aliyun_api = require('../../../utils/aliyun-api-gateway.js');
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },
  formsubmit:function(e){
    console.log(e.detail.value);

    const params = {
      url: 'https://api.link.aliyun.com/kvstore/get',
      apiVer: '1.1.0',
      param: {
        "key": e.detail.value.phone
      }
    }
    aliyun_api.request(params).then(function (res) {
      if (res.data) {
        var obj = JSON.parse(res.data)
        console.log('kv_password',obj.password);
        if (obj.password === e.detail.value.password) {
          try { //存入缓存
            wx.setStorageSync('accountInfo', e.detail.value)
            //wx.setStorageSync('password', e.detail.value.password)
          } catch (e) {
            console.log('fail')
          }

          wx.switchTab({
            url: '../../home/home',
          })
        } else {
          wx.showToast({
            title: '账号密码错误，请重新输入',
            icon: 'none',
            duration: 2000
          })
        }
      } else {
        wx.showToast({
          title: '账号不存在',
          icon: 'none',
          duration: 2000
        })
      }
    })
  },
  register:function(){
    wx.navigateTo({
      url: '../register/verify/verify',
    })
  }
})